import service from "@/utils/request"

import LoginWork from "@/utils/LoginWork" 

interface date{
    code:number,
    data:string,
    message:string
}

// 部门
export interface DepartmentInterface{
    deptName: string,
    deptNo: string
}

export const Department = () => {
    return service.get<any,DepartmentInterface[]>('/back/deptQuery')
}

// 领料明细查询
export interface MaterialRequisitionDetailsParms{
    deptName:string,
    deptNo:string,
    lotNo:string,
    mtlName:string,
    mtlTypeNo:string,
    pageNum:number,
    pageSize:number,
    slipDateEnd:string,
    slipDateStart:string,
    slipNo:string,
    slipType:string,
    userType:number
}

export interface MaterialRequisitionDetailsInterface{
    total?: number,
    dtos: dtos[ ]
}

interface dtos {
    companyId: string,
    slipType: string,
    lotNo: string,
    deptName: string,
    deptNo: string,
    mtlSpec: null,
    mtlUnit: string,
    slipNo: string,
    slipDate: string,
    mtlColor: string,
    mtlName: string,
    reqQty: number,
    actQty: number,
    ttlUsage: number,
    sendQty: null,
    unSendQty: null,
    stkQty: number,
    mtlNo: string,
    supplementNo: null,
    remark: null | string
}

export const MaterialRequisitionDetails = (parms:MaterialRequisitionDetailsParms) => {
    return service.put<any,any>('/pcFactorStockQuery/getDrawDetailQuery',parms)
}

// 实发明细查询
export interface ActualInventionInterface{
    dtos:dtosDate[]
    sum:number
}

export interface dtosDate{
    slipDate: string,
    actQty: null | number
}

export const ActualInvention = (id:string) => {
    return service.post<any,ActualInventionInterface>(`/pcFactorStockQuery/getDrawActQuery?id=${id}`)
}

// 替代材料查询
export interface substituteMaterialParms{
    mtlName:string,
    mtlTypeNo:string,
    pageNum:number,
    pageSize:number
}

export interface substituteMaterialInterface{
    total?: number,
    dtos: dtosList[]
}

interface dtosList{
    mtlNo: string,
    mtlName: string,
    mtlColor: string,
    mtlSpec: null,
    mtlUnit: string,
    stkPosition: null
}

export const substituteMaterial = async(parms:substituteMaterialParms) => {
    return service.put<any,substituteMaterialInterface>('/pcFactorStockQuery/getDrawReMtlQuery',parms)
}

// 分类
export interface AcquisitionSortInterface{
    typeNo: string,
    typeName: string
}

export const AcquisitionSort = () => {
    return service.get<any,AcquisitionSortInterface[]>('/back/getMtlType3')
}

// 整单删除
export const BlockDeletion = (slipNo:string,mtlNo:string,lotNo:string) => {
    return LoginWork.post<any,date>(`/pcFactorStockQuery/drawDetailCancel?slipNo=${slipNo}&mtlNo=${mtlNo}&lotNo=${lotNo}`)
}

// 材料替代查询
export interface MaterialSubstitutionQueryParms{
    mtlName1:string,
    mtlName2:string,
    pageNum:number,
    pageSize:number,
    slipNo:string
}

export interface MaterialSubstitutionQueryInterface{
    total?: number,
    dtos: dtosTableDateList[]
}

interface dtosTableDateList{
    slipNo: string,
    mtlNo: string,
    mtlName: string,
    mtlColor: string,
    mtlSpec: string,
    mtlUnit: string,
    qty: number,
    slipType2: string,
    mtlNo2: string,
    mtlName2: string,
    mtlColor2: string,
    mtlSpec2: string,
    mtlUnit2: string,
    qty2: number
}

export const MaterialSubstitutionQuery = (parms:MaterialSubstitutionQueryParms) => {
    return service.put<any,MaterialSubstitutionQueryInterface>('/pcFactorStockQuery/getDrawActMtlQuery',parms)
}

// 分类
export interface DepartmentInterfaceAcquisitionSortKle{
    typeNo: string,
    typeName: string
}

export const AcquisitionSortKle = () => {
    return service.post<any,DepartmentInterfaceAcquisitionSortKle[]>(`/back/getMtlType?levelCode=${2}`)
}

// 物料替代处理

export const MaterialSubstitutionProcessing = (parms:any,id:any) => {
    return LoginWork.post<any,date>(`/pcFactorStockQuery/draw/mtlReplace?id=${id}`,parms) 
}

// 数据回显查询
export const MaterialRequisitionConfirmation = (id:string) => {
    return LoginWork.get<any,any>(`/pcFactorStockQuery/draw/replace/mtlQuery?id=${id}`) 
}

// 数据删除
export const MaterialRequisitionConfirmationDelete = (id:string) => {
    return LoginWork.post<any,date>(`/pcFactorStockQuery/draw/replace/del?id=${id}`)
}